package javaweek6;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class comparatorLambda {
	
	class PersonSortable2 {
		private String name;
		private int age;
		
		public PersonSortable2(String name, int age) {
			this.name = name;
			this.age = age;
		}
		@Override
		public String toString() {
			return this.name+"-"+this.age;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public int getAge() {
			return age;
		}
		public void setAge(int age) {
			this.age = age;
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner (System.in);
		int n = sc.nextInt();
		PersonSortable2[] test=new PersonSortable2[n];
		PersonSortable2 o1;
		PersonSortable2 o2;
		Comparator<PersonSortable2> NameComparator = (o1 , o2) --> o1.getName().compareTo(o2.getName());
		Comparator<PersonSortable2> AgeComparator = (o1,o2) --> o1.getAge()-o2.getAge();
		for (int i = 0; i < n; i++) {
			test[i] = new PersonSortable2(sc.next(), sc.nextInt());
		}
		System.out.println("NameComparator:sort");
		Arrays.sort(test,NameComparator);
		for (PersonSortable2 personSortable1 : test) {
			System.out.println(personSortable1);
		}
		System.out.println("AgeComparator:sort");
		Arrays.sort(test,AgeComparator);
		for (PersonSortable2 personSortable2 : test) {
			System.out.println(personSortable2);
		}
		sc.close();
	}

}
/*public class Calculator {
  
    interface IntegerMath {
        int operation(int a, int b);   
    }
  
    public int operateBinary(int a, int b, IntegerMath op) {
        return op.operation(a, b);
    }
 
    public static void main(String... args) {
    
        Calculator myApp = new Calculator();
        IntegerMath addition = (a, b) -> a + b;
        IntegerMath subtraction = (a, b) -> a - b;
        System.out.println("40 + 2 = " +
            myApp.operateBinary(40, 2, addition));
        System.out.println("20 - 10 = " +
            myApp.operateBinary(20, 10, subtraction));    
    }
}

*/
